package com.neu.wangxiaoyang.servlet;

import com.neu.wangxiaoyang.service.QueryAllService;
import com.neu.wangxiaoyang.util.ExcelUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

@WebServlet(name = "DChServlet", urlPatterns = {"/DChServlet.do"})
public class DChServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        QueryAllService qs=new QueryAllService();
        HttpSession session=request.getSession();
        List<Map<String,Object>> list=qs.getAllVisit();
        OutputStream out=response.getOutputStream();
        String[] culName={"vst_ctime","dor_no","vst_reson","vst_ltime"};
        String[] labelNames={"到访时间","到访宿舍","到访原因","离开时间"};
        response.setHeader("content-disposition","attachment;filename=visit.xlsx");
        ExcelUtil.writeExcel(out,list,culName,labelNames);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
